import sys
import os
from PyQt5.QtWidgets import *
from PyQt5 import QtWidgets
#from start import Ui_MainWindow
#import start
from entry import *
#from framework.capture__ import *
from capture import *
from subprocess import call

def selectFile(self):
    fileName,fileType=QtWidgets.QFileDialog.getOpenFileName(None,"选取文件",os.getcwd(),"All Files(*);;Text Files(*.txt)")
    #ui.show_pushButton_2.setText(fileName)
    ui.lineEdit_2.setText(fileName)
    
def startCapture(self):
    # ClearTable()
    #flow = []
    # package = sniff(prn=PacketHandler, count=50)
    #startSniff(20)
    a=1

def run_capture(self):
    ui.pushButton.setText("开始抓包")
    if ui.lineEdit_2.text() == '':
        interface=ui.lineEdit.text()
        #print(interface)
        sniffcount=int(ui.spinBox.value())
        #print(sniffcount)
        startSniff(interface, sniffcount)
    elif ui.lineEdit_2.text() != '':
        filename=ui.lineEdit_2.text()
        sniff(offline=filename, prn=PacketHandler)
        #print(filename)

    #call(['python','capture.py'])

if __name__ == '__main__':
    app = QApplication(sys.argv)
    MainWindow = QMainWindow()
    ui = Ui_Dialog()
    ui.setupUi(MainWindow)
    MainWindow.show()
    #ui.pushButton.clicked.connect(startCapture)
    ui.pushButton_2.clicked.connect(selectFile)
    ui.pushButton.clicked.connect(run_capture)
    sys.exit(app.exec_())
